package com.tess.tboot.dao.mapper;

import com.tess.tboot.base.TbootBaseMapper;
import com.tess.tboot.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.session.RowBounds;

import java.util.List;
import java.util.Map;

/**
 * @author duanzonglong
 */
public interface UserMapper extends TbootBaseMapper<User> {
    /**
     * 通过用户名和状态获取用户
     *
     * @param username
     * @param status
     * @return
     */
    @Select("select * from t_user where username=#{username} and status = #{status}")
    List<User> findByUsernameAndStatus(@Param("username") String username, @Param("status") Integer status);

    /**
     * 通过状态和类型获取用户
     *
     * @param status
     * @param type
     * @return
     */
    @Select("select * from t_user where type=#{type} and status = #{status}")
    List<User> findByStatusAndType(@Param("status") Integer status, @Param("status") Integer type);


    @Select("<script>select count(1) from t_user where del_flag=0 " +
            "<when test='username!=null'> and username like '%'||#{username}||'%' </when>" +
            "<when test='mobile!=null'> and mobile = #{mobile} </when>" +
            "order by create_time desc</script>")
    int findByCond(Map<String,Object> params);

    @Select("<script>select * from t_user where del_flag=0 " +
            "<when test='username!=null'> and username like '%'||#{username}||'%' </when>" +
            "<when test='mobile!=null'> and mobile = #{mobile} </when>" +
            "order by create_time desc</script>")
    List<User> findByCondWithPage(Map<String,Object> params, RowBounds rowBounds);
}
